{
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## 10.10 \u901a\u8fc7\u5b57\u7b26\u4e32\u540d\u5bfc\u5165\u6a21\u5757\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "### \u95ee\u9898\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\u4f60\u60f3\u5bfc\u5165\u4e00\u4e2a\u6a21\u5757\uff0c\u4f46\u662f\u6a21\u5757\u7684\u540d\u5b57\u5728\u5b57\u7b26\u4e32\u91cc\u3002\u4f60\u60f3\u5bf9\u5b57\u7b26\u4e32\u8c03\u7528\u5bfc\u5165\u547d\u4ee4\u3002"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "### \u89e3\u51b3\u65b9\u6848\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\u4f7f\u7528importlib.import_module()\u51fd\u6570\u6765\u624b\u52a8\u5bfc\u5165\u540d\u5b57\u4e3a\u5b57\u7b26\u4e32\u7ed9\u51fa\u7684\u4e00\u4e2a\u6a21\u5757\u6216\u8005\u5305\u7684\u4e00\u90e8\u5206\u3002\u4e3e\u4e2a\u4f8b\u5b50\uff1a"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {},
      "outputs": [],
      "source": [
        "import importlib\nmath = importlib.import_module('math')\nmath.sin(2)"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {},
      "outputs": [],
      "source": [
        "mod = importlib.import_module('urllib.request')\nu = mod.urlopen('http://www.python.org')"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "import_module\u53ea\u662f\u7b80\u5355\u5730\u6267\u884c\u548cimport\u76f8\u540c\u7684\u6b65\u9aa4\uff0c\u4f46\u662f\u8fd4\u56de\u751f\u6210\u7684\u6a21\u5757\u5bf9\u8c61\u3002\u4f60\u53ea\u9700\u8981\u5c06\u5176\u5b58\u50a8\u5728\u4e00\u4e2a\u53d8\u91cf\uff0c\u7136\u540e\u50cf\u6b63\u5e38\u7684\u6a21\u5757\u4e00\u6837\u4f7f\u7528\u3002"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\u5982\u679c\u4f60\u6b63\u5728\u4f7f\u7528\u7684\u5305\uff0cimport_module()\u4e5f\u53ef\u7528\u4e8e\u76f8\u5bf9\u5bfc\u5165\u3002\u4f46\u662f\uff0c\u4f60\u9700\u8981\u7ed9\u5b83\u4e00\u4e2a\u989d\u5916\u7684\u53c2\u6570\u3002\u4f8b\u5982\uff1a"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {},
      "outputs": [],
      "source": [
        "import importlib\n# Same as 'from . import b'\nb = importlib.import_module('.b', __package__)"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "### \u8ba8\u8bba\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\u4f7f\u7528import_module()\u624b\u52a8\u5bfc\u5165\u6a21\u5757\u7684\u95ee\u9898\u901a\u5e38\u51fa\u73b0\u5728\u4ee5\u67d0\u79cd\u65b9\u5f0f\u7f16\u5199\u4fee\u6539\u6216\u8986\u76d6\u6a21\u5757\u7684\u4ee3\u7801\u65f6\u5019\u3002\u4f8b\u5982\uff0c\u4e5f\u8bb8\u4f60\u6b63\u5728\u6267\u884c\u67d0\u79cd\u81ea\u5b9a\u4e49\u5bfc\u5165\u673a\u5236\uff0c\u9700\u8981\u901a\u8fc7\u540d\u79f0\u6765\u52a0\u8f7d\u4e00\u4e2a\u6a21\u5757\uff0c\u901a\u8fc7\u8865\u4e01\u52a0\u8f7d\u4ee3\u7801\u3002"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\u5728\u65e7\u7684\u4ee3\u7801\uff0c\u6709\u65f6\u4f60\u4f1a\u770b\u5230\u7528\u4e8e\u5bfc\u5165\u7684\u5185\u5efa\u51fd\u6570__import__()\u3002\u5c3d\u7ba1\u5b83\u80fd\u5de5\u4f5c\uff0c\u4f46\u662fimportlib.import_module() \u901a\u5e38\u66f4\u5bb9\u6613\u4f7f\u7528\u3002"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\u81ea\u5b9a\u4e49\u5bfc\u5165\u8fc7\u7a0b\u7684\u9ad8\u7ea7\u5b9e\u4f8b\u89c110.11\u5c0f\u8282"
      ]
    }
  ],
  "metadata": {
    "kernelspec": {
      "display_name": "Python 3",
      "language": "python",
      "name": "python3"
    },
    "language_info": {
      "codemirror_mode": {
        "name": "ipython",
        "version": 3
      },
      "file_extension": ".py",
      "mimetype": "text/x-python",
      "name": "python",
      "nbconvert_exporter": "python",
      "pygments_lexer": "ipython3",
      "version": "3.7.1"
    },
    "toc": {
      "base_numbering": 1,
      "nav_menu": {},
      "number_sections": true,
      "sideBar": true,
      "skip_h1_title": true,
      "title_cell": "Table of Contents",
      "title_sidebar": "Contents",
      "toc_cell": false,
      "toc_position": {},
      "toc_section_display": true,
      "toc_window_display": true
    }
  },
  "nbformat": 4,
  "nbformat_minor": 2
}